package com.wyp168.leetcode;

/**
 * @ClassName FirstMissingPositive
 * @Description TODO  2022-10-07 --- 重检
 * @Author wyp168
 * @Descrption: leetcode 41.缺失的第一个正整数 【hard】
 * @Date 2022/10/4 21:01
 */
public class FirstMissingPositiveSolution {
    public static void main(String[] args) {
        FirstMissingPositiveSolution solution = new FirstMissingPositiveSolution();

        int[] nums = {2147483647};

        System.out.println(solution.firstMissingPositive(nums));
    }

    public static final int MAX_ARRAY_SIZE = (int) Math.pow(2,31);

    public int firstMissingPositive(int[] nums) {

        //定义一个数组，存放正整数出现的次数
        int[] bucket = new int[MAX_ARRAY_SIZE];

        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > 0)
                bucket[nums[i]] = 1;
        }

        int index = 1;
        while (index < bucket.length && bucket[index] == 1) {
            index ++;
        }

        return index;
    }
}
